1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.kandula;
19
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.util.Properties;
23
24 /***
25 * @author Dasarath Weeratunge, Hannes Erven, Georg Hicker
26 *
27 */
28 public class KandulaConfig {
29
30 private static final String PROPERTY_FILE = "kandula.properties";
31
32 private static final String LOCAL_SERVICE__PROPERTY = "kandula.localService";
33
34 private static final String PREFERRED_SERVICE__PROPERTY = "kandula.preferredCoordinationService";
35
36 private static KandulaConfig instance = new KandulaConfig();
37
38 private Properties properties = null;
39
40 private KandulaConfig() {
41 this.properties = new Properties();
42 loadProperties();
43 }
44
45 public static KandulaConfig getInstance() {
46 return instance;
47 }
48
49 private void loadProperties() {
50 InputStream in = getClass().getClassLoader().getResourceAsStream(PROPERTY_FILE);
51
52 try {
53 this.properties.load(in);
54 in.close();
55 } catch (IOException e) {
56 e.printStackTrace();
57 throw new RuntimeException(e);
58 }
59 }
60
61 public String getContext() {
62 return this.properties.getProperty(LOCAL_SERVICE__PROPERTY);
63 }
64
65 /***
66 * Return the configured local kandula services endpoint base URL, eg.
67 * http://test1.kandula.apache.org:8280/axis/services/
68 * @return String-URL
69 */
70 public String getLocalServicesURL() {
71 return this.properties.getProperty(LOCAL_SERVICE__PROPERTY);
72 }
73
74 /***
75 * Return the configured preferred kandula coordination services endpoint base URL, eg.
76 * http://my-favorite-coordinator.bar.foo.org:8180/axis/services/
77 * @return String-URL
78 */
79 public String getKandulaServicesURL(){
80 final String externalURL = this.properties.getProperty(PREFERRED_SERVICE__PROPERTY);
81
82 if (externalURL != null && externalURL.length()>0)
83 return externalURL;
84
85 return getContext();
86 }
87 }